<div class="row">
    <p id="list-title">{{.PageName}}</p>
</div>

<form id="roleForm" action="{{.URL}}{{.RecordID}}?action={{.Action}}" method="post" class="post-form form-horizontal {{if .Readonly}}form-disabled{{else}}form-edit{{end}}" role="form">
    <div class="row">
        {{if .RecordID}} {{if .Readonly}}
        <a href="{{.URL}}{{.RecordID}}?action=edit" class="btn btn-success fa fa-pencil pull-left form-edit-btn">&nbsp编辑</a>
        <a href="{{.URL}}?action=create" type="buttom" class="btn btn-success fa fa-plus pull-left form-create-btn">&nbsp新建</a>{{end}}{{end}}
        <button type="submit" form="roleForm" class="btn btn-primary fa fa-save pull-left form-save-btn">&nbsp保存</button> {{if .Readonly}}
        <button type="button" class="btn btn-danger fa fa-remove  pull-left form-cancel-btn">&nbsp取消</button> {{else}}
        <a href="{{.URL}}" class="btn btn-danger fa fa-remove  pull-left">&nbsp取消</a> {{end}}
        <a href="{{.URL}}" class="btn btn-info fa fa-list pull-left">&nbsp列表</a>
    </div>
    {{ .xsrf }} {{if .RecordID}}
    <input type="hidden" data-type="int" class="{{.FormField}}" name="recordID" id="record-id" value="{{.RecordID}}"> {{end}}

    <div class="row">
        <div class="col-md-6">
            <fieldset>
                <legend>基本信息</legend>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="name" class="col-md-4 control-label label-start">角色名称<span class="required-input">&nbsp*</span></label>
                            <div class="col-md-8">
                                <p class="p-form-control">{{if .Role}} {{.Role.Name}} {{end}}</p>
                                <input data-type="string" class="{{.FormField}} form-control" id="name" name="Name" type="text" {{if .Role}} value="{{.Role.Name}}" {{end}} />
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="col-md-6">
            <fieldset>
                <legend>用户信息</legend>
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="permissionIds" class="col-md-2 control-label label-start">该角色的用户</label>
                            <div class="col-md-10">
                                <p class="p-form-control">{{if and .Role .Role.Users}} {{range $j,$attrVal := .Role.Users}}<a class='display-block label label-primary'>{{$attrVal.Name}}</a> {{end}}{{end}}</p>
                                <select data-type='array_int' data-name='UserIds' name='UserIds' id='userIds' multiple='multiple' class='{{.FormField}} form-control select-user'>
                                    {{if and .Role  .Role.Users}} 
                                        {{range $j,$attrVal :=  .Role.Users}}
                                            <option value=" {{$attrVal.ID}} " selected="selected ">{{$attrVal.Name}}</option>
                                        {{end}}
                                    {{end}}
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
    </div>
    <div class="row ">
        <div class="col-md-6 ">
            <fieldset>
                <legend>权限信息</legend>
                <div class="row ">
                    <div class="col-md-12 ">
                        <div class="form-group ">
                            <label for="permissionIds " class="col-md-2 control-label label-start ">角色拥有权限</label>
                            <div class="col-md-10 ">
                                <p class="p-form-control ">{{if and .Role .Role.Permissions}} {{range $j,$attrVal := .Role.Permissions}}<a class='display-block label label-primary'>{{$attrVal.Name}}</a> {{end}}{{end}}</p>
                                <select data-type='array_int' data-name='PermissionIds' name='PermissionIds' id='permissionIds' multiple='multiple' class='{{.FormField}} form-control select-permission'>
                                    {{if and .Role  .Role.Permissions}} 
                                        {{range $j,$attrVal :=  .Role.Permissions}}
                                            <option value="{{$attrVal.ID}} " selected="selected ">{{$attrVal.Name}}</option>
                                        {{end}}
                                    {{end}}
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="col-md-6 ">
            <fieldset>
                <legend>菜单信息</legend>
                <div class="row ">
                    <div class="col-md-12 ">
                        <div class="form-group ">
                            <label for="menuIds " class="col-md-2 control-label label-start ">角色可见的菜单</label>
                            <div class="col-md-10 ">
                                <p class="p-form-control ">{{if and .Role .Role.Menus}} {{range $j,$attrVal := .Role.Menus}}<a class='display-block label label-primary'>{{$attrVal.Name}}</a> {{end}}{{end}}</p>
                                <select data-type='array_int' data-name='MenuIds' name='MenuIds' id='menuIds' multiple='multiple' class='{{.FormField}} form-control select-menu'>
                                    {{if and .Role  .Role.Menus}} 
                                        {{range $j,$attrVal :=  .Role.Menus}}
                                            <option value="{{$attrVal.ID}} " selected="selected ">{{$attrVal.Name}}</option>
                                        {{end}}
                                    {{end}}
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
    </div>
</form>